<?php
class DataUtil{

	const VALUE_YES='1';
	const VALUE_NO='0';
	
	private static $_timeCache=array();

	public static function getOptionYesNo(){
		return array(self::VALUE_YES=>'Yes',self::VALUE_NO=>'No');
	}

	public static function getOptionYesNoEmpty($val=NULL){
		$options = array(''=>'',self::VALUE_YES=>'Yes',self::VALUE_NO=>'No');
		if($val != null){
			return $options[$val];
		}
		return $options;
	}
		
	public static function getProductNames($type) {
		$names=Product::model()->findAll(
			array(
				'select'=>'name',
				'condition'=>'type=:type',
				'params'=>array(':type'=>$type),
				'distinct'=>true
			));
		$result = CHtml::listData($names, 'name', 'name');
		return $result;
	}
	
	public static function getProductModels($type, $name) {
		$names=Product::model()->findAll(
			array(
				'select'=>'id, model',
				'condition'=>'type=:type AND name=:name',
				'params'=>array(':type'=>$type, ':name'=>$name),
				'distinct'=>true
			));
		$result = CHtml::listData($names, 'id', 'model');
		return $result;
	}	
	
	
	
	
	public static function getStores() {
		$types=Store::model()->findAll(array('select'=>'type','distinct'=>true));
		$result=array(''=>'');
		foreach ($types as $type) {
			$result[$type->type]=$type->type;
		}
		return $result;
	}
	
	public static function getStates(){
		return array(
			''=>'',
			'NSW'=>'NSW',
			'ACT'=>'ACT',
			'VIC'=>'VIC',
			'QLD'=>'QLD',
			'SA'=>'SA',
			'WA'=>'WA',
			'TAS'=>'TAS',
			'NT'=>'NT',
		);
	}
}